<?php

class AvisoDao extends Dao {

    public function injectDependencies() {

    }

    public function findByUser($Usuario) {
        $this->initConnection();
        $StSql = TQuery::getSqlFindNoticesByUser($Usuario);
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotices = array();
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $ArNotices[] = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return $ArNotices;
    }

    public function findById($IDAviso) {
        $this->initConnection();
        $StSql = TQuery::getSqlFindNoticesById($IDAviso);
        $tQuery = $this->tMysqli->exec($StSql);
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $Notice = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return isset($Notice) ? $Notice : false;
    }

    public function findAll() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindAllNotices();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotices = array();
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $ArNotices[] = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return $ArNotices;
    }

    public function findActiveNotices() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindActiveNotices();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotices = array();
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $ArNotices[] = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return $ArNotices;
    }

    public function findExperedNotices() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindExperedNotices();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotices = array();
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $ArNotices[] = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return $ArNotices;
    }

    public function findFutureNotices() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindFutureNotices();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotices = array();
        while($ArNoticeData = mysqli_fetch_assoc($tQuery)) {
            $ArNotices[] = new Aviso($ArNoticeData);
        }
        $this->closeConnection();
        return $ArNotices;
    }

    public function save($ArDados) {
        $IDUsuario = Dracosys::getLoggedUser()->getIDUsuario();
        $this->initConnection();
        $StSql = TQuery::getSqlInsertNotice($ArDados, $IDUsuario);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function update($ArDados) {
        $this->initConnection();
        $StSql = TQuery::getSqlUpdateNotice($ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

}

?>
